from pydantic import BaseModel, ConfigDict
from typing import List, Any
from datetime import datetime
from fastapi import status


class ResultSchema(BaseModel):
    code: int = status.HTTP_200_OK
    message: str = "success"
    requestId: str = ""
    data: Any = None
    

class CommoditySchema(BaseModel):
    # 把整形，转换为字符串类型
    model_config = ConfigDict(coerce_numbers_to_str=True, from_attributes=True)
    id: str
    title: str
    price: float
    covers: List[str]
    detail: str
    created_time: datetime
    

class SeckillSchema(BaseModel):
    # 把整形，转换为字符串类型
    model_config = ConfigDict(coerce_numbers_to_str=True, from_attributes=True)
    id: str
    sk_price: float
    start_time: datetime
    end_time: datetime
    create_time: datetime
    max_sk_count: int
    sk_per_max_count: int
    stock: int
    commodity: CommoditySchema|None
    

class SeckillListSchema(BaseModel):
    seckills: List[SeckillSchema]


class SeckillPageSchema(BaseModel):
    list: List[SeckillSchema]
    total: int
    page: int
    size: int


class OrderSchema(BaseModel):
    # 把整形，转换为字符串类型
    model_config = ConfigDict(coerce_numbers_to_str=True, from_attributes=True)
    id: str
    create_time: datetime
    status: int
    count: int
    amount: float
    address: str
    seckill: SeckillSchema
    

class OrderListSchema(BaseModel):
    orders: List[OrderSchema]
